<template>
	<view class="home">
		<swiper indicator-dots circular>
			<swiper-item v-for="item in swipers" :key="item.id">
				<image :src="item.img"></image>
			</swiper-item>
		</swiper>
		<!-- 导航区 -->
		<view class="nav">
			<view class="nav_item" v-for="(item,index) in navs" :key="index" @click="navItemClick(item.path)">
				<view :class="item.icon">

				</view>
				<text>{{item.title}}</text>
			</view>
			
			
         </view>
		<!-- 推荐商品区 -->
		<view class="hot_goods">
			<view class="tit">推荐商品</view>
			<goods-list @goodsItemClick="goGoodsDetail" :goods="goods"></goods-list>
 

		</view>

	
	</view>

	</view>
</template>

<script>
import goodsList from '../../pages/components/goods-list/goods-list.vue'
	export default {
		data() {
			return {
				swipers: [],
				navs: [{
						icon: 'iconfont icon-ziyuan',
						title: '动漫社区',
						path: '/pages/goods/goods'
					},
					{
						icon: 'iconfont icon-guanyuwomen',
						title: '联系我们',
						path: '/pages/contact/contact'
					},
					{
						icon: 'iconfont icon-tupian',
						title: '社区图片',
						path: '/pages/pics/pics'
					},
					{
						icon: 'iconfont icon-shipin',
						title: '学习视频',
						path: '/pages/videos/videos'
					}
				],
				goods: []

			}
		},
		onLoad() {
			this.getSwipers()
			this.gethotGoods()

		},
		components:{
			"goods-list":goodsList
		},
		methods: {

			// 获取轮播图的数据
			async getSwipers() {
				const res = await this.$myRuquest({
					url: '/api/getlunbo'
				})

				this.swipers = res.data.message
			},
			// 获取热门商品列表数据
			async gethotGoods() {
				const res = await this.$myRuquest({
					url: '/api/getgoods?pageindex=1'
				})
				this.goods = res.data.message
			},
			// 导航点击的处理函数
			 navItemClick(url){
				 uni.navigateTo({
				 	url
					

				 })
				 
			 },
			 // 导航到商品详情页
			 goGoodsDetail (id) {
			 	uni.navigateTo({
			 		url: '/pages/goods-detail/goods-detail?id='+id
			 	})
			 }
		}
	}
</script>

<style>
	.home swiper {

		width: 750rpx;
		height: 380rpx;
}
.home swiper image {
	width: 100%;
	height: 100%;
}

	.nav {

		display: flex;
		justify-content: center;

	}

	.nav_item {
		width: 25%;
		text-align: center;



	}

	.nav_item view {
		width: 120rpx;
		height: 120rpx;
		background: #b50e03;
		border-radius: 60rpx;
		margin: 10px auto;
		line-height: 120rpx;
		color: #fff;
		font-size: 50rpx;
	}

	.nav_item text {
		font-size: 30rpx;

	}

	.icon-tupian {

		font-size: 45rpx;
	}

	.hot_goods {
		background: #eee;
		overflow: hidden;

	}

	.tit {
		height: 50px;
		line-height: 50px;
		color: #b50e03;
		text-align: center;
		letter-spacing: 20px;
		background: #fff;
		margin: 7rpx 0;
	}

	
</style>
